package com.lams.action.system;

import java.util.HashMap;
import java.util.Map;

import com.lams.action.SubAction;
import com.lams.service.system.IParameterFacade;
import com.lams.util.ResultEntity;

public class ParameterAction extends SubAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = 7321341337315743251L;
	private IParameterFacade pf;
	private String ORG_NO;
	private String PARAMETER_ID;
	private String PARAMETER_NAME;
	private String PARAMETER_VALUE;
	private String REMARK;
	private Map parameters = new HashMap();
	//private SOrg unit;
	//private SParameter param;
	
	public IParameterFacade getPf() {
		return pf;
	}

	public void setPf(IParameterFacade pf) {
		this.pf = pf;
	}
	
	public String select(){
		//Map parameters = ActionContext.getContext().getParameters();
		ResultEntity result = pf.findByUnit(this.getStart(), this.getLimit(),String.valueOf(parameters.get("ORG_NO")));
		result.setSuccess(true);
		result.setLimit(this.getLimit());
		result.setStart(this.getStart());
		System.out.println(ResultEntity.decode(result));
		this.setResult(ResultEntity.decode(result));
		return SUCCESS;
	}
	public String saveOrUpdate(){
		//Map parameters = ActionContext.getContext().getParameters();
		ResultEntity result = new ResultEntity();
		try{
			pf.saveOrUpdate(parameters);
			result.setMessage("保存成功");
			result.setSuccess(true);
		}catch(Exception e){
			result.setSuccess(false);
			result.setMessage("保存失败");
		}
		this.setResult(ResultEntity.decode(result));
		return SUCCESS;
	}
	public String delete(){
		//Map parameters = ActionContext.getContext().getParameters();
		pf.delete(parameters);
		ResultEntity result = new ResultEntity();
		result.setSuccess(true);
		result.setMessage("");
		return SUCCESS;
	}
	public String checkParameName(){
		//Map parameters = ActionContext.getContext().getParameters();
		ResultEntity result =  pf.checkParameterName(String.valueOf(parameters.get("PARAMETER_NAME")));
		this.setResult(ResultEntity.decode(result));
		return SUCCESS;
	}

	public String getORG_NO() {
		return ORG_NO;
	}

	public void setORG_NO(String oRG_NO) {
		ORG_NO = oRG_NO;
		parameters.put("ORG_NO", "".equals(oRG_NO)|| oRG_NO == null ? "-1" : oRG_NO);
	}

	public String getPARAMETER_ID() {
		return PARAMETER_ID;
	}

	public void setPARAMETER_ID(String pARAMETER_ID) {
		PARAMETER_ID = pARAMETER_ID;
		parameters.put("PARAMETER_ID", pARAMETER_ID);
	}

	public String getPARAMETER_NAME() {
		return PARAMETER_NAME;
	}

	public void setPARAMETER_NAME(String pARAMETER_NAME) {
		PARAMETER_NAME = pARAMETER_NAME;
		parameters.put("PARAMETER_NAME", pARAMETER_NAME);
	}

	public String getPARAMETER_VALUE() {
		return PARAMETER_VALUE;
	}

	public void setPARAMETER_VALUE(String pARAMETER_VALUE) {
		PARAMETER_VALUE = pARAMETER_VALUE;
		parameters.put("PARAMETER_VALUE", pARAMETER_VALUE);
	}

	public String getREMARK() {
		return REMARK;
	}

	public void setREMARK(String rEMARK) {
		REMARK = rEMARK;
		parameters.put("REMARK", rEMARK);
	}
}
